<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Title</title>
    <link rel="stylesheet" href="assets/css/bootstrap.css" />
    <link href="assets/bootstrap-table/bootstrap-table.css" rel="stylesheet" />

    <script src="assets/js/jquery-2.0.3.min.js"></script>
    <script src="assets/js/bootstrap.js"></script>
    <script src="assets/bootstrap-table/bootstrap-table.js"></script>
    <script src="assets/bootstrap-table/bootstrap-table-zh-CN.js"></script>
    <script src="assets/js/tableutils.js"></script>
    <script src="assets/js/utils.js"></script>
    <script src="assets/layer/layer.js"></script>
</head>
<body>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <div class="main-content">
            <div class="page-content">
                <div style="padding: 0px 15px;">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="panel panel-default">
                                <div class="panel-heading">查询条件</div>
                                <div class="panel-body">
                                    <form id="formSearch" class="form-horizontal">
                                        <div class="form-group" style="margin-top: 15px">
                                            <label class="control-label col-sm-1" for="project_code">产品编码</label>
                                            <div class="col-sm-2">
                                                <input type="text" class="form-control" id="project_code" name="project_code"/>
                                            </div>
                                            <label class="control-label col-sm-1" for="app_code">app编码</label>
                                            <div class="col-sm-2">
                                                <input type="text" class="form-control" id="app_code" name="app_code"/>
                                            </div>
                                            <label class="control-label col-sm-1" for="app_name">app名称</label>
                                            <div class="col-sm-2">
                                                <input type="text" class="form-control" id="app_name" name="app_name"/>
                                            </div>
                                            <div class="col-sm-3" style="text-align: left;">
                                                <button type="button" style="margin-left: 50px"
                                                        id="btn_query" class="btn btn-primary">查询</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <div id="rentTable">
                                <div class="btn-group toolbar">
                                    <button id="btn_add" type="button" class="btn btn-success">
                                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                                    </button>
                                    <button id="btn_delete" type="button" class="btn btn-danger">
                                        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                                    </button>
                                </div>
                                <table></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function() {

        var operateEvents = {
            'click #del' : function(e, value, row, index) {
                var id = row.id;
                if (id != null) {
                    layer.msg('是否删除？', {
                        time: 0 //不自动关闭
                        ,btn: ['确定', '取消']
                        ,yes: function(index){
                            layer.close(index);
                            ajaxs('./DRent/' + id, 'DELETE', null, true, function(data) {
                                layer.msg(data.message);
                                $("#rentTable table").bootstrapTable('refresh');
                            });
                        }
                    });
                } else {
                    layer.msg("数据错误请联系管理员...");
                }
            },
            'click #upd' : function(e, value, row, index) {
                var id = row.id;
                if (id != null) {
                    $.FormDialog({
                        form_url : './dRentUpdate',
                        title : '修改客户信息',
                        id : id,
                        fullscreen: true
                    });
                } else {
                    layer.msg("数据错误请联系管理员...");
                }
            },
            'click #lock' : function(e, value, row, index) {
                var id = row.id;
                if (id != null) {
                    layer.msg(row.islock===0?'是否锁定？':'是否解锁？', {
                        time: 0 //不自动关闭
                        ,btn: ['确定', '取消']
                        ,yes: function(index){
                            layer.close(index);
                            ajaxs('./DRent/lock/' + id, 'GET', null, true, function(data) {
                                layer.msg(data.message);
                                $("#rentTable table").bootstrapTable('refresh');
                            });
                        }
                    });
                } else {
                    layer.msg("数据错误请联系管理员...");
                }
            }
        };
        var columns = [{
            field : 'checkStatus',
            checkbox : true
        }, {
            field : 'id',
            visible : false
        }, {
            field : 'projectCode',
            title : '产品编码'
        }, {
            field : 'appCode',
            title : 'app编码'
        }, {
            field : 'appName',
            title : 'app名称'
        }, {
            field : 'extender.showPackType',
            title : '打包类型'
        }, {
            field : 'packagePath',
            title : '打包文件路径'
        }, {
            field : 'logPath',
            title : '应用日志路径'
        }, {
            field : 'operate',
            title : '操作',
            events : operateEvents,
            formatter : operateFormatter
            // 自定义方法，添加操作按钮
        }];
        function stateDeal(value, row, index) {
            if(row.islock===0){
                return '<span class="label label-success">未锁定</span>';
            }else {
                return '<span class="label label-danger">已锁定</span>';
            }
        }
        var defaultDetailCallBack = function(index,row,$detail) {
            var $htm = $("<div><div>");
            var htm = "";

            htm += "<div class='col-sm-12'>";
            htm += "<table class='table  table-bordered'>";
            htm += "<tr><th colspan='12' class='center'  style='text-align: center'>客户详情</th></tr>";

            htm += "<tr>";
            htm += "<th>联系电话:</th>";
            htm += "<td>" + row.rentPhone + "</td>";
            htm += "<th>联系地址:</th>";
            htm += "<td>" + row.rentAddress + "</td>";
            htm += "<th>客户网站</th>";
            htm += "<td>" + row.rentWebsite + "</td>";
            htm += "<th>客户描述</th>";
            htm += "<td>" + row.rentDescribe + "</td>";
            htm += "</tr>";

            htm += "<tr>";
            htm += "<th>更新人:</th>";
            htm += "<td>" + row.updateUser + "</td>";
            htm += "<th>更新时间:</th>";
            htm += "<td>" + row.extender.showUpdateTime + "</td>";
            htm += "</tr>";

            htm += "</table>";
            htm += "</div>";
            $htm.append(htm);
            $detail.append($htm);
        };
        var queryParams = function(params) {
            var temp = { // 这里的键的名字和控制器的变量名必须一至，这边改动，控制器也需要改成一样的
                limit : params.limit, // 页面大小
                offset : params.offset // 当前页码
            };
            return temp;
        };
        function operateFormatter(value, row, index) { // 赋予的参数
            var myArray=new Array(3);
            myArray[1] = '<button id="upd" class="btn btn btn-link btn-sm"><span style="color: #00ACED">修改</span></button>';
            myArray[2] = '<button id="del" class="btn btn btn-link btn-sm"><span style="color: #d9534f">删除</span></button>';
            return myArray.join('');
        }

        // 1.初始化Table
        var oTable = new TableInit('#rentTable', "./DApp/searchByPage", columns,
            'POST', 'server', queryParams,defaultDetailCallBack);
        oTable.Init();
        // 2.初始化Button的点击事件
        var oButtonInit = new ButtonInit();
        oButtonInit.Init();
    });

    var ButtonInit = function() {
        var oInit = new Object();
        var postdata = {};

        oInit.Init = function() {
            // 初始化页面上面的按钮事件
            $("#btn_query").click(function() {
                $("#rentTable table").bootstrapTable('refresh');
            });
            $("#btn_add").click(function() {
                $.FormDialog({
                    form_url : './dRentAdd',
                    title : '新增客户信息',
                    fullscreen: true
                });
            });
            /*$("#btn_update").click(function() {
                $.FormDialog({
                    form_url : './TRentUpdate',
                    title : '修改客户信息',
                    isclose : false
                });
            });*/
            $("#btn_delete").click(function() {
                var a = $("#rentTable table").bootstrapTable('getSelections');
                if (a.length > 0) {
                    layer.msg('是否删除？', {
                        time: 0 //不自动关闭
                        ,btn: ['确定', '取消']
                        ,yes: function(index){
                            layer.close(index);
                            var a = $("#rentTable table").bootstrapTable('getSelections');
                            var ids = '';
                            a.map(function(value, index) {
                                ids = ids + value.id + ',';
                            });
                            ajaxs('./DRent/' + ids, 'DELETE', null,
                                true, function(data) {
                                    if(data.state=='success') {
                                        layer.msg(data.message);
                                        $("#rentTable table").bootstrapTable('refresh');
                                    } else {
                                        layer.msg(data.message);
                                    }
                                });
                        }
                    });
                } else {
                    layer.msg("请选择一条信息进行删除");
                }
            });
        };
        return oInit;
    };
</script>
</html>
